package fr.emse.tatiana.corpus;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.*;

import fr.emse.tatiana.display.DisplayCell;
import fr.emse.tatiana.display.DisplayDate;
import fr.emse.tatiana.display.DisplayFileWriter;
import fr.emse.tatiana.replayable.Anchor;
import fr.emse.tatiana.replayable.ReplayableEvent;

import au.com.bytecode.opencsv.CSVReader;

public class AudioSegWriter {
	
	String xmlname;

	public AudioSegWriter(String xmlname) {
		this.xmlname = xmlname;
	}

	public void convert(String path,String docname) {
        DisplayFileWriter writer = new DisplayFileWriter(xmlname);
        
	    try {
	    	 BufferedReader in
	    	   = new BufferedReader(new FileReader(path));
	        String line = null;
	        int pos = 0;
	        while((line = in.readLine())!=null){
	        	if (line.startsWith("/")) continue;
	        	pos++;
	        	writer.newItem();
	        	String[] elems = line.split("\\s+",-1);
	        	long millis = (long) Float.parseFloat(elems[1])*1000;
	        	long end = (long) Float.parseFloat(elems[2])*1000;
	        	writer.newInfo("time", "", new DisplayDate(millis,end-millis));
	        	writer.newInfo("speaker", "", "unknown");
	        	writer.newInfoFromString("src-anchor", new Anchor(docname,pos).toString());
	        }
	        writer.close();
	        
	    } catch (Exception e) {
	        // TODO Auto-generated catch block
	        e.printStackTrace();
	    }
	
	}
		
}


